#!/dis/sh
# story states: _buy≤2 _bound  _examine≤2 _examined  _develop≤4  _developed  _attest≤2 _attested  _incorporate≤1 _incorporated
# task states: _todo _writing≤2 _valid
# bug states: _seen _rooting≤2 _quashed

(f re) = $*

if {~ $#* 0} {
	f = bedactwvsrq
	re = .
}

if {~ $#* 1} {
	re = $f
	f = bedactwvsrq
}

if {~ $f '*p*'} {
	nb -x ' _ping ' $re | sed 's,'^`{pwd}^'/,,'
}

if {~ $f '*c*'} {
	nb -x ' _incorporated ' $re | sed 's,'^`{pwd}^'/,,'
	
	nb -x ' _incorporate ' $re | sed 's,'^`{pwd}^'/,,'
	count=`{nb -x ' _incorporate ' $re | sed 's,'^`{pwd}^'/,,' | grep -v 'todate:' | wc -l}
	load expr 
	if {~ ${expr $count 1 gt} 1} {echo too many}
}

if {~ $f '*b*'} {
	nb -x ' _bound ' $re | sed 's,'^`{pwd}^'/,,'
	
	nb -x ' _buy ' $re | sed 's,'^`{pwd}^'/,,'
	count=`{nb -x ' _buy ' $re | sed 's,'^`{pwd}^'/,,' | grep -v 'todate:' | wc -l}
	load expr 
	if {~ ${expr $count 2 gt} 1} {echo too many}
}

if {~ $f '*a*'} {
	nb -x ' _attested ' $re | sed 's,'^`{pwd}^'/,,'
	
	nb -x ' _attest ' $re | sed 's,'^`{pwd}^'/,,'
	count=`{nb -x ' _attest ' $re | sed 's,'^`{pwd}^'/,,' | grep -v 'todate:' | wc -l}
	load expr 
	if {~ ${expr $count 2 gt} 1} {echo too many}
}

if {~ $f '*e*'} {
	nb -x ' _examined ' $re | sed 's,'^`{pwd}^'/,,'

	nb -x ' _examine ' $re | sed 's,'^`{pwd}^'/,,'
	count=`{nb -x ' _examine ' $re | sed 's,'^`{pwd}^'/,,' | grep -v 'todate:' | wc -l}
	load expr 
	if {~ ${expr $count 2 gt} 1} {echo too many}
}

if {~ $f '*d*'} {
	nb -x ' _developed ' $re | sed 's,'^`{pwd}^'/,,'

	nb -x ' _develop ' $re | sed 's,'^`{pwd}^'/,,'
	count=`{nb -x ' _develop ' $re | sed 's,'^`{pwd}^'/,,' | grep -v 'todate:' | wc -l}
	load expr 
	if {~ ${expr $count 4 gt} 1} {echo too many}
}

# tasks
if {~ $f '*v*'} {
	nb -x ' _valid ' $re | sed 's,'^`{pwd}^'/,,'
}

if {~ $f '*t*'} {
	nb -x ' _todo ' $re | sed 's,'^`{pwd}^'/,,'
}

if {~ $f '*w*'} {
	nb -x ' _writing ' $re | sed 's,'^`{pwd}^'/,,'
	count=`{nb -x ' _writing ' $re | sed 's,'^`{pwd}^'/,,' | grep -v 'todate:' | wc -l}
	load expr 
	if {~ ${expr $count 4 gt} 1} {echo too many}
}

# bugs
if {~ $f '*q*'} {
	nb -x ' _quashed ' $re | sed 's,'^`{pwd}^'/,,'
}

if {~ $f '*s*'} {
	nb -x ' _seen ' $re | sed 's,'^`{pwd}^'/,,'
}

if {~ $f '*r*'} {
	nb -x ' _rooting ' $re | sed 's,'^`{pwd}^'/,,'
	count=`{nb -x ' _rooting ' $re | sed 's,'^`{pwd}^'/,,' | grep -v 'todate:' | wc -l}
	load expr 
	if {~ ${expr $count 2 gt} 1} {echo too many}
}

exit 0
